//
//  WXPAlreadyAuthAmendBankCardView.m
//  修改银行卡 区域
//
//  Created by wxp on 2025/3/10.
//

#import "WXPAlreadyAuthAmendBankCardView.h"

@implementation WXPAlreadyAuthAmendBankCardView

#pragma mark - lazy
- (UIView *)viewBack{
   if (_viewBack == nil) {
       _viewBack = [UIView new];
       _viewBack.backgroundColor = COLOR_WHITE;
       _viewBack.userInteractionEnabled = true;
       [GlobalMethod setRoundView:_viewBack color:[UIColor whiteColor] numRound:16 width:0];
   }
   return _viewBack;
}
- (UILabel *)labelTitle{
   if (_labelTitle == nil) {
       _labelTitle = [UILabel new];
       _labelTitle.textColor = COLOR_BLACK;
       _labelTitle.font = [UIFont boldSystemFontOfSize:16];
   }
   return _labelTitle;
}
- (UIView *)lineTitle{
   if (_lineTitle == nil) {
       _lineTitle = [UIView new];
       _lineTitle.widthHeight = XY(36, 6);
       [GlobalMethod setRoundView:_lineTitle color:[UIColor clearColor] numRound:6/2 width:0];
       _lineTitle.backgroundColor = COLOR_PRIMARY;
   }
   return _lineTitle;
}
- (UIView *)lineView{
   if (_lineView == nil) {
       _lineView = [UIView new];
       _lineView.backgroundColor = COLOR_LINE;
   }
   return _lineView;
}

- (UIView *)viewErrorBack{
    if (_viewErrorBack == nil) {
        _viewErrorBack = [UIView new];
        _viewErrorBack.backgroundColor = COLOR_RED;
        _viewErrorBack.alpha = 0.2;
    }
    return _viewErrorBack;
}
- (UILabel *)labelError{
    if (_labelError == nil) {
        _labelError = [UILabel new];
        _labelError.textColor = COLOR_RED;
        _labelError.fontNum = 12;
    }
    return _labelError;
}
- (UIImageView *)imageError{
    if (_imageError == nil) {
        _imageError = [UIImageView new];
        _imageError.image = [UIImage imageNamed:@"icon-error-red"];
        _imageError.widthHeight = XY(14, 14);
    }
    return _imageError;
}
- (UILabel *)labelContent{
    if (_labelContent == nil) {
        _labelContent = [UILabel new];
        _labelContent.textColor = COLOR_BLACK;
        _labelContent.fontNum = 12;
        _labelContent.numberOfLines = 0;
        _labelContent.lineSpace = 3;
    }
    return _labelContent;
}
-(UIButton *)btnAmend{
    if (_btnAmend == nil) {
        _btnAmend = [UIButton buttonWithType:UIButtonTypeCustom];
        _btnAmend.tag = 1;
        [_btnAmend addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        _btnAmend.backgroundColor = COLOR_PRIMARY;
        [_btnAmend setTitleColor:COLOR_BLACK forState:UIControlStateNormal];
        _btnAmend.titleLabel.font = [UIFont systemFontOfSize:14];
        _btnAmend.height = BUTTON_HEIGHT;
        [GlobalMethod setRoundView:_btnAmend color:[UIColor clearColor] numRound:BUTTON_HEIGHT/2 width:0];
        [_btnAmend setTitle:@"Ir a modificar" forState:(UIControlStateNormal)];
    }
    return _btnAmend;
}

#pragma mark - 初始化
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.widthHeight = XY(SCREEN_WIDTH, 0);
        self.backgroundColor = [UIColor clearColor];
        self.userInteractionEnabled = true;
        [self addSubView];
    }
    return self;
}
//添加subview
- (void)addSubView{
    [self addSubview:self.viewBack];
    [self.viewBack addSubview:self.lineTitle];
    [self.viewBack addSubview:self.labelTitle];
    [self.viewBack addSubview:self.lineView];
    [self.viewBack addSubview:self.viewErrorBack];
    [self.viewBack addSubview:self.labelError];
    [self.viewBack addSubview:self.imageError];
    [self.viewBack addSubview:self.labelContent];
    [self.viewBack addSubview:self.btnAmend];
    [self resetView];
}

#pragma mark 点击事件
- (void)btnClick:(UIButton *)sender{
    [NSObject clickFeedback];
    [sender addClickAnimate];
    switch (sender.tag) {
        case 1:
        {
            [Global_Nav pushVCName:@"WXPBankCardVC" animated:true];
        }
            break;
            
        default:
            break;
    }
}

#pragma mark - 刷新view
- (void)resetView{
    //刷新view
    self.viewBack.widthHeight = XY(SCREEN_WIDTH-LEFT_MARDIN*2, 0);
    
    [self.labelTitle fitTitle:@"Descongelar la cuota" variable:0];
    self.labelTitle.leftTop = XY(LEFT_MARDIN, LEFT_MARDIN);
    self.lineTitle.leftBottom = XY(self.labelTitle.left-1, self.labelTitle.bottom);
    self.lineView.widthHeight = XY(self.viewBack.width-2*LEFT_MARDIN, 1);
    self.lineView.centerXTop = XY(self.viewBack.width/2, self.lineTitle.bottom+13);
    
    self.viewErrorBack.height = 20;
    self.viewErrorBack.leftTop = XY(0, self.lineView.bottom+LEFT_MARDIN);
    self.imageError.leftCenterY = XY(self.labelTitle.left, self.viewErrorBack.centerY);
    [self.labelError fitTitle:@"Transacción fallada！" variable:0];
    self.labelError.leftCenterY = XY(self.imageError.right+5, self.imageError.centerY);
    self.viewErrorBack.width = self.labelError.right+LEFT_MARDIN;
    UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:self.viewErrorBack.bounds byRoundingCorners:(UIRectCornerTopRight | UIRectCornerBottomRight) cornerRadii:CGSizeMake(self.viewErrorBack.height/2, self.viewErrorBack.height/2)];
    CAShapeLayer *maskLayer = [CAShapeLayer layer];
    maskLayer.path = path.CGPath;
    self.viewErrorBack.layer.mask = maskLayer;
    
    [self.labelContent fitTitle:@"Compruebe la información de su cuenta bancaria" variable:self.viewBack.width-2*self.labelTitle.left];
    self.labelContent.leftTop = XY(self.labelTitle.left, self.viewErrorBack.bottom+LEFT_MARDIN);
    self.btnAmend.width = self.viewBack.width-2*_labelTitle.left;
    self.btnAmend.centerXTop = XY(self.viewBack.width/2, self.labelContent.bottom+20);
    
    self.viewBack.height = self.btnAmend.bottom+18;
    self.viewBack.centerXTop = XY(self.width/2, 0);
    self.height = self.viewBack.bottom+LEFT_MARDIN;

}

@end
